package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.ForgotPasswordHandler;
import com.cungmua.app.model.request.ForgotPasswordRequest;
import com.cungmua.app.model.response.ForgotPasswordResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/25/14.
 */
public class ForgotPasswordTask extends AuthenticatedTask<ForgotPasswordRequest, Void, ForgotPasswordResponse> {
    private Context context;
    private ForgotPasswordHandler handler;

    public ForgotPasswordTask(Context context, ForgotPasswordHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected ForgotPasswordResponse doInBackground() throws RetrofitError {
        ForgotPasswordRequest request=params[0];
        return CungMuaAPI.getService().forgotPassword(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(ForgotPasswordResponse forgotPasswordResponse) {
        handler.onForgotPassword(forgotPasswordResponse);
    }
}
